const http = require('http');
const https = require('https');
 
http.createServer((req, res) => {
    const options = {
        hostname: 'www.cloud-dahua.com', // 目标服务器的域名或IP
        port: 443,                  // 目标服务器的端口
        path: req.url,              // 请求的路径
        method: req.method,         // 请求的方法
        headers: req.headers        // 请求头，可以在此处添加或修改请求头
    };
 
    const proxyReq = https.request(options, proxyRes => {
        res.writeHead(proxyRes.statusCode, proxyRes.headers);
        proxyRes.pipe(res);
    });
 
    proxyReq.on('error', (e) => {
        console.error(`Problem with request: ${e.message}`);
        res.statusCode = 500;
        res.end(`Error: ${e.message}`);
    });
 
    req.pipe(proxyReq);
 
}).listen(3000); // 代理服务器监听的端口
 
console.log('Proxy server is running on port 3000');